home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / disk / misc / TransADF.lha / TransADF / Source / errors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-05  |  4.2 KB  |  195 lines

  1. /* errors.c - Output various error messages
  2. ** Copyright (C) 1997,1998 Karl J. Ots
  3. ** 
  4. ** This program is free software; you can redistribute it and/or modify
  5. ** it under the terms of the GNU General Public License as published by
  6. ** the Free Software Foundation; either version 2 of the License, or
  7. ** (at your option) any later version.
  8. ** 
  9. ** This program is distributed in the hope that it will be useful,
  10. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ** GNU General Public License for more details.
  13. ** 
  14. ** You should have received a copy of the GNU General Public License
  15. ** along with this program; if not, write to the Free Software
  16. ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17. */
  18.  
  19. #include <exec/types.h>
  20. #include <exec/errors.h>
  21. #include <devices/trackdisk.h>
  22. #include <dos/dos.h>
  23. #include <clib/dos_protos.h>
  24.  
  25. #include "errors.h"
  26. #include "main.h"
  27. #include "zlib.h"
  28.  
  29.  
  30. /* Private functions */
  31. void reportTDError (BYTE TDError);
  32.  
  33.  
  34. /*
  35. ** Output a DOS error value, as returned by IoErr(), as a text string
  36. ** to StdErr.
  37. */
  38. void reportDOSError (LONG DOSError)
  39. {
  40.   char ErrorString[80];
  41.   
  42.   if (Fault (DOSError, "DOS Error", ErrorString, 79))
  43.     FPrintf (StdErr, "%s.\n", ErrorString);
  44.   else
  45.     FPrintf (StdErr, "DOS Error: %ld.\n", DOSError);
  46. }
  47.  
  48.  
  49. /* 
  50. ** Output an IO Error, as returned by DoIO(), as a text 
  51. ** string to stderr.
  52. */
  53. void reportIOError (BYTE IOError)
  54. {
  55.   STRPTR ErrStr;
  56.   
  57.   /* Check to see if this is a TrackDisk error */
  58.   if ((IOError >= TDERR_NotSpecified) && (IOError <= TDERR_PostReset))
  59.   {
  60.     reportTDError (IOError);
  61.     return;
  62.   }
  63.   
  64.   switch (IOError) {
  65.   case IOERR_OPENFAIL:
  66.     ErrStr = "Open failure";
  67.     break;
  68.   case IOERR_ABORTED:
  69.     ErrStr = "IO aborted";
  70.     break;
  71.   case IOERR_NOCMD:
  72.     ErrStr = "Unknown command";
  73.     break;
  74.   case IOERR_BADLENGTH:
  75.     ErrStr = "Bad length";
  76.     break;
  77.   case IOERR_BADADDRESS:
  78.     ErrStr = "Bad address";
  79.     break;
  80.   case IOERR_UNITBUSY:
  81.     ErrStr = "Unit is busy";
  82.     break;
  83.   case IOERR_SELFTEST:
  84.     ErrStr = "Self test failure";
  85.     break;
  86.   default:
  87.     ErrStr = "Unknown Error";
  88.   }
  89.   
  90.   FPrintf (StdErr, "%s (%ld).\n", ErrStr, IOError);
  91. }
  92.  
  93.  
  94. /*
  95. ** Output a TrackDisk IO Error, as returned by DoIO(),
  96. ** as a text string to stderr.
  97. */
  98. void reportTDError (BYTE TDError)
  99. {
  100.   STRPTR ErrStr;
  101.  
  102.   switch (TDError) {
  103.   case TDERR_NotSpecified:
  104.     ErrStr = "Not specified";
  105.     break;
  106.   case TDERR_NoSecHdr:
  107.     ErrStr = "No sector header";
  108.     break;
  109.   case TDERR_BadSecPreamble:
  110.     ErrStr = "Bad sector preamble";
  111.     break;
  112.   case TDERR_BadSecID:
  113.     ErrStr = "Bad sector ID";
  114.     break;
  115.   case TDERR_BadHdrSum:
  116.     ErrStr = "Bad header checksum";
  117.     break;
  118.   case TDERR_BadSecSum:
  119.     ErrStr = "Bad sector checksum";
  120.     break;
  121.   case TDERR_TooFewSecs:
  122.     ErrStr = "Not enough sectors"; 
  123.     break;
  124.   case TDERR_BadSecHdr:
  125.     ErrStr = "Bad sector header";
  126.     break;
  127.   case TDERR_WriteProt:
  128.     ErrStr = "Disk is write protected";
  129.     break;
  130.   case TDERR_DiskChanged:
  131.     ErrStr = "No disk in drive";
  132.     break;
  133.   case TDERR_SeekError:
  134.     ErrStr = "Seek error";
  135.     break;
  136.   case TDERR_NoMem:
  137.     ErrStr = "Out of memory";
  138.     break;
  139.   case TDERR_BadUnitNum:
  140.     ErrStr = "No such unit";
  141.     break;
  142.   case TDERR_BadDriveType:
  143.     ErrStr = "Unknown drive type";
  144.     break;
  145.   case TDERR_DriveInUse:
  146.     ErrStr = "Drive is in use";
  147.     break;
  148.   case TDERR_PostReset:
  149.     ErrStr = "Post Reset";
  150.     break;
  151.   }
  152.   
  153.   FPrintf (StdErr, "%s (%ld).\n", ErrStr, TDError);
  154. }
  155.  
  156.  
  157.  
  158. /*
  159. ** Output a Zlib error as a test string.
  160. */
  161. void reportZLibError (LONG ZLibError)
  162. {
  163.   STRPTR ErrStr;
  164.   
  165.   switch (ZLibError) {
  166.   case Z_ERRNO:
  167.     ErrStr = "Error Number";
  168.     break;
  169.   case Z_STREAM_ERROR:
  170.     ErrStr = "Stream Error";
  171.     break;
  172.   case Z_DATA_ERROR:
  173.     ErrStr = "Data Error";
  174.     break;
  175.   case Z_MEM_ERROR:
  176.     ErrStr = "Memory Error";
  177.     break;
  178.   case Z_BUF_ERROR:
  179.     ErrStr = "Buffer Error";
  180.     break;
  181.   case Z_VERSION_ERROR:
  182.     ErrStr = "Version Error";
  183.     break;  
  184.   default:
  185.     ErrStr = NULL;
  186.   }
  187.  
  188.   FPuts (StdErr, "ZLib Error: ");
  189.   if (ErrStr)
  190.     FPuts (StdErr, ErrStr);
  191.   else
  192.     FPrintf (StdErr, "Unknown (%ld)", ZLibError);
  193.   FPuts (StdErr, ".\n");
  194. }
  195.